/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
//作者:AKPower
//算法:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll n, m;
ll x, y;
ll p[20];
ll g[5][5];
void init()
{
    p[0] = 1;
    for (int i = 1; i <= 19; i++)
        p[i] = p[i - 1] * 2;
    g[0][0] = 3, g[0][1] = 0, g[0][2] = 0, g[0][3] = 2;
    g[1][0] = 2, g[1][1] = 1, g[1][2] = 1, g[1][3] = 3;
    g[2][0] = 0, g[2][1] = 2, g[2][2] = 2, g[2][3] = 1;
    g[3][0] = 1, g[3][1] = 3, g[3][2] = 3, g[3][3] = 0;
}
void fun(ll s, ll state, ll k)
{
    //printf("%lld %lld %lld %lld %lld\n", x, y, s, state, k);
    if (k == 0)
        return;
    ll num = s / (p[k - 1] * p[k - 1]);
    //printf("num %lld \n", num);
    if (state == 0)
    {
        if (num == 0)
        {
        }
        else if (num == 1)
        {
            y += p[k - 1];
        }
        else if (num == 2)
        {
            x += p[k - 1];
            y += p[k - 1];
        }
        else if (num == 3)
        {
            x += p[k - 1];
        }
    }
    else if (state == 1)
    {
        if (num == 0)
        {
            y += p[k - 1];
        }
        else if (num == 1)
        {
        }
        else if (num == 2)
        {
            x += p[k - 1];
        }
        else if (num == 3)
        {
            x += p[k - 1];
            y += p[k - 1];
        }
    }
    else if (state == 2)
    {
        if (num == 0)
        {
            x += p[k - 1];
        }
        else if (num == 1)
        {
        }
        else if (num == 2)
        {
            y += p[k - 1];
        }
        else if (num == 3)
        {
            x += p[k - 1];
            y += p[k - 1];
        }
    }
    else if (state == 3)
    {
        if (num == 0)
        {
            y += p[k - 1];
        }
        else if (num == 1)
        {
            x += p[k - 1];
            y += p[k - 1];
        }
        else if (num == 2)
        {
            x += p[k - 1];
        }
        else if (num == 3)
        {
        }
    }
    s -= (num * p[k - 1] * p[k - 1]);
    k--;
    ll state1 = g[state][num];
    fun(s, state1, k);
}
int main()
{
    IOS;
    init();
    while (scanf("%lld%lld", &n, &m) != EOF)
    {
        m--;
        x = 1, y = 1;
        for (int i = 0; i <= 19; i++)
        {
            if (p[i] == n)
            {
                fun(m, 0, (ll)i);
                break;
            }
        }
        printf("%lld %lld\n", x, y);
    }

    return 0;
}
